import { cur_event_check } from '../../../Classes/cla_event_check';
import { forBindEventThis } from '../../../Func/forBindEventThis';
import { quick_func_float_dataMana } from './cla_quick_func_float_dataMana';

const quick_func_float_operateTag = 'quick_func_float_operate';

export class quick_func_float_operate extends quick_func_float_dataMana {
  get [Symbol.toStringTag]() {
    return quick_func_float_operateTag;
  }

  constructor() {
    super();

    forBindEventThis(this);

    this.eventM.addEventListen(
      this.dom_border,
      'dblclick',
      this.eventBind.quick_func_float_border_dom_dbclick_self
    );

    this.eventM.addEventListen(
      window as any,
      'click',
      this.eventBind.window_white_space_click_self
    );

    this.freeze_window_click();
  }

  /**
   * 快速功能 点击 动画 显示 当前页面中的 快速功能
   */
  async quick_func_float_border_dom_dbclick_self() {
    if (this.targetEl == undefined) {
      await this.no_single_func();

      return;
    }
    // let targetEl_id = this.get_targetEl_id_for_quick_func_float();

    // if (targetEl_id == null) {
    //   await this.no_single_func();

    //   return;
    // }

    // let cur_target_dom = normalizeContainer(targetEl_id);

    // if (cur_target_dom == null) {
    //   await this.no_single_func();

    //   return;
    // }

    // this.targetEl = cur_target_dom;

    /**
     * 禁用 双击事件
     */
    this.freeze_dom_border_dbClick();

    await this.open_view_container_func();
  }

  /**
   * 焦点元素 空白处 点击 取消 当前 操作
   */
  async window_white_space_click_self(event: MouseEvent) {
    if (
      cur_event_check.set_cur_event(event).is_child_emit(this.dom_border).result
    ) {
      return;
    }

    this.freeze_window_click();

    await this.cancel_view_container_func();
  }
}
